/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package general;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;


public class conectarBD {

    public  ResultSet rs;
    public  Connection con;
    public  Statement stmt;
    public  String driver;
    public  String conneccionString;
    public  String usuario;
    public  String clave;
     public boolean conectar()
    {   
             driver = "org.postgresql.Driver";
             conneccionString = "jdbc:postgresql://localhost:5432/labUno";
             usuario = "postgres";
             clave = "123456";//
            try {
                Class.forName(driver);
                return true;
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(conectarBD.class.getName()).log(Level.SEVERE, null, ex);
                return false;
            }
    }

    public void desconectar()
    {
        try {
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(conectarBD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    public boolean accionSql(String sql)
    {
        try {
            con = DriverManager.getConnection(conneccionString, usuario, clave);
            stmt = (Statement) con.createStatement();
            rs = stmt.executeQuery(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(conectarBD.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }


}
